package cn.wzvtc.ch5_validation;

import cn.wzvtc.ch5_validation.validation.Add;
import cn.wzvtc.ch5_validation.validation.Update;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;

@RestController
@Validated
public class TestController {

    @PostMapping("/testvalidated")
    public String testvalidated1(@NotBlank(message = "用户名不能为空") String name,
                                 @Min(value = 0, message = "年龄不能小于0")
                                     @Max(value = 120, message = "年龄不能大于120岁") Integer age) {
        return name + "/" + age;
    }

    @PostMapping("/testvalidated3add")
    public User testvalidated3add(@Validated({Add.class}) User user) {
        return user;
    }

    @PostMapping("/testvalidated4update")
    public User testvalidated4update(@Validated({Update.class}) User user) {
        return user;
    }
}
